package com.ks.gopush.cli;

import java.util.List;

/**
 * Created by gustavo on 2015/6/4.
 */
public class PushClient {

    private static GoPushCli goPushCli;

    public static void init(String host, Integer port, String key, int heartbeat){

        if (goPushCli == null) {

            goPushCli = new GoPushCli(host, port, key, heartbeat, new Listener() {
                @Override
                public void onOpen() {

                    System.out.println("onOpen = duang");

                }

                @Override
                public void onClose() {

                    System.out.println("onClose = close");

                }

                @Override
                public void onOnlineMessage(PushMessage message) {

                    System.out.println("online message = " + message.toString());
                }

                @Override
                public void onOfflineMessage(List<PushMessage> messages) {

                    for (PushMessage message : messages) {

                        System.out.println("offline message = " + message.toString());
                    }
                }

                @Override
                public void onError(Throwable e, String message) {

                    System.out.println("error = " + e.toString());
                    e.printStackTrace();
                }
            });
        }
        new Thread(){
            @Override
            public void run() {
                super.run();
                goPushCli.start(false, 0, 0);

            }
        }.start();

    }


    public static void stop(){
        if (goPushCli != null) {
            goPushCli.destroy();
        }
    }
}
